<template>
    <div>
        <h2>房号修改</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td>
                        <input type="text" v-model="model.HouseTypeName">
                    </td>
                </tr>


                <tr>
                    <td>房号名称</td>
                    <td>
                        <input type="text" v-model="model.HouseNoName">
                    </td>
                </tr>


                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="status" value="1" v-model="model.State">上架
                        <input type="radio" name="status" value="0" v-model="model.State">下架
                    </td>
                </tr>



                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" class="btn btn-success" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import axios from 'axios'
const router = useRouter()
const route = useRoute()

let model = reactive({
    Id: route.query.Id,
    "HouseTypeName": '',
    "HouseNoName": '',
    "State": 1,

})



onMounted(() => {
    HouseNoAll();
})


const HouseNoAll = () => {
    axios({
        url: 'https://localhost:7154/api/HouseNo/HouseNoAll',
        method: 'get',
        params: {
            Id: route.query.Id,
        }
    })
        .then(res => {
            console.log(res);
            model.HouseTypeName=res.data.HouseTypeName;
            model.HouseNoName=res.data.HouseNoName;
            model.State=res.data.State;
        })
        .catch(err => {
            console.log(err);
        })
}


//修改
const ok = () => {
    
axios({
url: 'https://localhost:7154/api/HouseNo/HouseNoUpd',
method: 'put',
data: model,
})
.then(res => {
    console.log(res);
   
     if(res.data>0){
        alert('修改成功')
        router.push('/houseNoList')
    }
    else{
        alert('修改失败')
    }


})

.catch(err => {
    console.log(err);
})






}



</script>

<style scoped></style>